const mysql = require('mysql')

const options = {
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'acgcarton'
}
const query = (sql, params) => {
    return new Promise((resolve, reject) => {
       const conn = mysql.createConnection(options)
        //连接数据库
        conn.connect();
        conn.query(sql, params, (err, results) => {
            if(err) {
                console.log("err: ", err)
                reject("err:" +err)
            } else {
                resolve(results)
            }
        })
        conn.end();
    })
}

module.exports = {query}